
! ! !  PARA USAR COM LMDER: método semi analítico para o jacobiano

	subroutine fcn2(m,n,x,fvec,fjac,ldfjac,iflag)
	include 'param_dim.inc'
	real*8 x(n),xplus(npar_max)
	double precision fobj
	integer iavalfunct,n,m,ldfjac,metodo
	double precision fvec(m),fjac(ldfjac,n),fvecplus(NRCX)

	real*8 fvecaux(NX),xaux(npar_max)

        integer count1,count2,count_rate,count_max

	data iavalfunct/0/
	iavalfunct=iavalfunct+1

	metodo = 2
	if(iflag .eq. 0)then

            write(4,*) '_______________________________________'
            fobj=resid(x,fvec,fjac,m,n,ldfjac,iflag,metodo)
            write(4,*) '_______________________________________'

	else if(iflag .eq. 1)then
            call system_clock(count1,count_rate,count_max)
!             write(4,*) 'fcn2 - calculo do vetor residuo - FVEC'
            fobj=resid(x,fvec,fjac,m,n,ldfjac,iflag,metodo)
            call system_clock(count2,count_rate,count_max)
            r=(count2-count1)
            write(4,*)'tempo avaliacao: (s)',r/count_rate
            write(4,*)

	else if(iflag .eq. 2)then
            call system_clock(count1,count_rate,count_max)
!             write(4,*) 'fcn2 - calculo do jacobiano de f - FJAC'
            fobj=resid(x,fvec,fjac,m,n,ldfjac,iflag,metodo)
            call system_clock(count2,count_rate,count_max)
            r=(count2-count1)
            write(4,*)'tempo Jacobiano: (s)',r/count_rate
            write(4,*)
	endif

 1000	format(8f10.4)
 1001	format(104f10.4)
 300    format(10f10.6)
 1130   format(22x,3f14.6)
	return
	end	


